package cn.licoy.wdog.common.util.sendSmsCode;

import cn.licoy.wdog.common.annotation.SysLogs;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;

/**
 * @author Sunne
 * Create time 2018/6/22 10:39
 * @return null
 **/
public class SendSmsUtil {
    // 企业ID
    private static String CorpID = "CDLK00334";
    // 密码
    private static String Pwd = "ss1103@";

    /**
     * 发送方法 其他方法同理 返回1都是提交成功 -1发送失败
     */
    public static int sendSMS(String mobile, String content) {
        BufferedReader in = null;
        int inputLine = -1;
        try {
            String send_content = URLEncoder.encode(content + "【优捷健康】", "GBK");// 发送内容
            URL url = new URL("http://yzm.mb345.com/ws/BatchSend2.aspx?CorpID="
                    + CorpID + "&Pwd=" + Pwd + "&Mobile=" + mobile
                    + "&Content=" + send_content + "&SendTime=&cell=");
            in = new BufferedReader(new InputStreamReader(url.openStream()));
            String[] split = in.readLine().split(",");
            if (split != null && split.length > 0) {
                // 大于0的数字	发送成功
                inputLine = Integer.parseInt(split[0]);
            } else {
                inputLine = -1;
            }
            return inputLine;
        } catch (Exception e) {
            inputLine = -1;
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return inputLine;
    }
}
